function [Ldir] = Lstart
% 5/9/2014  Parker MacCready
%
% A function to be invoked at the start of any primary MATLAB code anywhere
% in the LiveOcean folder.  It returns a structure Ldir that has handy
% pathnames, and it adds useful toolboxes to the path.
%
% Typical usage (depending on directory location in LiveOcean/):
%
% addpath('../alpha'); Ldir = Lstart;
%
% it relies on the existence of a text file RUN_INFO.txt
% in which each line has two strings: an item name and its value
% separated by whitespace

%% Read environment variables
%
% New version
fid = fopen('RUN_INFO.csv','r');
C = textscan(fid,'%s%s','Delimiter',',');
fclose(fid);
items = C{1};
values = C{2};
for ii = 1:length(items)
    if(strcmp(items{ii},'GRIDNAME'))
        Ldir.gridname = values{ii};
    elseif(strcmp(items{ii},'TAG'))
        Ldir.tag = values{ii};
    end
end
Ldir.gtag = [Ldir.gridname,'_',Ldir.tag];

% and get the parent
which_home = getenv('HOME');
switch which_home
    case '/Users/PM3'
        Ldir.parent = '/Users/PM3/Documents/';
    case '/home/parker'
        Ldir.parent = '/data1/parker/';
    otherwise
        disp('Trouble filling out environment variables in Ldir')
end

%% set locations of things
Ldir.home = [Ldir.parent,'LiveOcean/'];
Ldir.out = [Ldir.parent,'LiveOcean_output/'];
%
Ldir.res = [Ldir.home,'preamble/make_resources/'];

% Give access to, e.g., the coastline file used in Z_addcoast.m
addpath([Ldir.home,'shared/data']);

% Paths to shared code assumed to be available by many programs
addpath([Ldir.home,'shared/mexcdf/mexnc']);
addpath([Ldir.home,'shared/mexcdf/snctools']);
addpath([Ldir.home,'shared/seawater']);
addpath([Ldir.home,'shared/Z_functions']);


